<!--
# coding=UTF-8
# Copyright (c) 2025 Bird Software Solutions Ltd
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
#    Neil Mackenzie - initial API and implementation
#    Benjamin Arfa - improvements
#
-->
{% extends 'base.html' %}

{% block content %}
<h1>View Combinations</h1>
<a href="{% url 'pybirdai:workflow_task' task_number=2 operation='review' %}">Back to Review</a>

{% if messages %}
<ul class="messages">
    {% for message in messages %}
    <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
    {% endfor %}
</ul>
{% endif %}

<div class="table-container">
    <table>
        <thead>
            <tr>
                <th>Maintenance Agency</th>
                <th>Combination ID</th>
                <th>Code</th>
                <th>Name</th>
                <th>Description</th>
                <th>Valid From</th>
                <th>Valid To</th>
                <th>Version</th>
                <th>Combination Type</th>
            </tr>
        </thead>
        <tbody>
            {% for form in formset %}
            <tr>
                <td>{{ form.maintenance_agency_id.value }}</td>
                <td>{{ form.combination_id.value }}</td>
                <td>{{ form.code.value }}</td>
                <td>{{ form.name.value }}</td>
                <td>{{ form.description.value }}</td>
                <td>{{ form.valid_from.value }}</td>
                <td>{{ form.valid_to.value }}</td>
                <td>{{ form.version.value }}</td>
                <td>{{ form.combination_type.value }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>

<!-- Pagination -->
<div class="pagination">
    <span class="step-links">
        {% if page_obj.has_previous %}
            <a href="?page=1">&laquo; first</a>
            <a href="?page={{ page_obj.previous_page_number }}">previous</a>
        {% endif %}

        <span class="current">
            Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
        </span>

        {% if page_obj.has_next %}
            <a href="?page={{ page_obj.next_page_number }}">next</a>
            <a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a>
        {% endif %}
    </span>
</div>

<style>
    .table-container {
        width: 100%;
        overflow-x: auto;
        margin-bottom: 1em;
    }
    table {
        border-collapse: collapse;
        width: 100%;
        min-width: 1500px; /* Adjusted for fewer columns */
    }
    th, td {
        border: 1px solid #ddd;
        padding: 8px;
        text-align: left;
    }
    th {
        background-color: #f2f2f2;
        position: sticky;
        top: 0;
    }
    .pagination {
        margin-top: 20px;
    }
</style>
{% endblock %}
